<template>
  <div class="tag-page">
    <header class="header">
      <button class="back-btn" @click="$router.push('/back')">
        <span>‹</span>
        返回
      </button>
      <h1>音乐标签</h1>
    </header>
    
    <div class="content">
      <div class="input-section">
        <label class="input-label">标签内容</label>
        <textarea 
          v-model="tagContent" 
          placeholder="添加标签: a [id] [tag]
删除标签: d [id] [tag]
-- 多个id或tag以英文逗号分隔"
          class="tag-textarea"
          rows="13"
        ></textarea>
      </div>
      
      <div class="button-group">
        <button class="btn btn-clear" @click="clearContent">
          <span class="btn-icon">🗑️</span>
          清空
        </button>
        <button class="btn btn-confirm" @click="tagOpr">
          <span class="btn-icon">✓</span>
          确认
        </button>
      </div>
    </div>
  </div>
</template>

<script>
import { apiService } from '../utils/http'
import { tools } from '../utils/tools'

export default {
  name: 'MusicTag',
  data() {
    return {
      tagContent: ''
    }
  },
  methods: {
    async tagOpr() {
      if (!this.tagContent.trim()) {
        alert('请输入标签内容')
        return
      }
      
      try {
        const headers = {token: `${tools.getTokenFromCookie()}`}
        const { res, isAuthenticated } = await tools.authApiCall(
          () => apiService.post('/TagOpr', {value: this.tagContent}, { headers }),
          this.$router,
          this.$route
        )
        if (isAuthenticated) {
          if (!res.data.status) {
            console.error('标签操作返回失败:', res.data)
            alert('操作返回失败，请重试')
          }
        }
      } catch (error) {
        console.error('标签操作失败:', error)
        alert('操作失败，请重试')
      }
    },
    
    clearContent() {
      this.tagContent = ''
    }
  }
}
</script>

<style scoped>
.tag-page {
  min-height: 100vh;
  background: #f8f9fa;
}

.header {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  color: white;
}

.back-btn {
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: white;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  transition: background 0.3s ease;
}

.back-btn:hover {
  background: rgba(255, 255, 255, 0.3);
}

.header h1 {
  font-size: 20px;
  font-weight: 600;
}

.content {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.input-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.input-label {
  font-size: 16px;
  font-weight: 500;
  color: #333;
  padding-left: 4px;
}

.tag-textarea {
  width: 100%;
  min-height: 200px;
  padding: 16px;
  border: 1px solid #e0e0e0;
  border-radius: 12px;
  font-size: 16px;
  line-height: 1.5;
  resize: vertical;
  background: white;
  transition: border-color 0.3s ease;
}

.tag-textarea:focus {
  outline: none;
  border-color: #667eea;
  box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.1);
}

.tag-textarea::placeholder {
  color: #999;
}

.button-group {
  display: flex;
  gap: 12px;
}

.btn {
  flex: 1;
  padding: 16px 20px;
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn-clear {
  background: #f8f9fa;
  color: #666;
  border: 1px solid #e0e0e0;
}

.btn-clear:hover {
  background: #e9ecef;
  transform: translateY(-1px);
}

.btn-confirm {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

.btn-confirm:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}

.btn-icon {
  font-size: 18px;
}
</style>
